package com.mjh.manager;

import java.util.HashMap;
import java.util.Map;
import org.apache.log4j.Logger;
import com.mjh.bean.Discuss;
import com.mjh.comm.page.Pager;
import com.mjh.config.GlobalConfig;
import com.mjh.dao.DiscussDAO;

public class DiscussManager {

	public static Logger log = Logger.getLogger(DiscussManager.class);
	
	private DiscussDAO dao = new DiscussDAO();
	
	public int addDiscuss(Discuss discuss){
		return dao.insert(discuss);
	}
	
	public int updateDiscussId(int discussId){
		return dao.updateDiscussId(discussId);
	}
	
	public int delDiscuss(int id){
		return dao.delete(id);
	}

	public int delDiscussByArticle(int articleId){
		return dao.deleteByArticle(articleId);
	}
	
	public Discuss getDiscuss(int id){
		return dao.select(id);
	}
	
	public Pager<Discuss> listAll(int pagerNo, Map<String,Object> para){
		HashMap<String,Object> parameter = new HashMap<String,Object>();
		Pager<Discuss> pager = new Pager<Discuss>();
		pager.setPageNo(pagerNo);
		pager.setPageSize(GlobalConfig.getSysConfig().getDiscussPageSize());
		parameter.put("pageStart", pager.getStartNo());
		parameter.put("pageSize", pager.getPageSize());
		parameter.putAll(para);
		pager.setTotalNum(dao.selectCount(parameter));
		pager.setPageData(dao.selectForList(parameter));
		return pager;
	}
}
